<?php
/**
*文章管理
*2013-7-5
*@盘古大叔
*
*/
class PageAction extends Action
{
	public function preMethod()
	{
		R("Mayijie/check_admin");
		$perm_key = session('admin_perm');
		$perm_arr = explode(",",$perm_key);
		if(!in_array(8,$perm_arr)){
			$this->error("无权操作");
		}
	}

	//文章管理菜单
	public function menu(){
		$this->display();
	}
    
	/*购物指南-start*/
	public function zhinan(){
		$Zhinan=M('Page_zhinan');
		$action=$this->_get('action');
		if($action=='add'){
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Zhinan->add($data)){
				unset($data);
				$this->success("添加成功！");
			}
		}else if($action=='edit'){
			$map['id']=$this->_get('id');
			$this->zhinan=$Zhinan->where($map)->find();
			$this->display('edit_zhinan');
		}else if($action=='save'){
			$map['id']=$this->_get('id');
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Zhinan->where($map)->save($data)){
				unset($data);
				$this->success("修改成功！");
			}
		}else{
			$this->zhinan=$Zhinan->order('time desc')->select();
			$this->display();
		}
	}
	/*购物指南-end*/
    
	/*购物条款-start*/
	public function tiaokuan(){
		$Tk=M('Page_tk');
		$action=$this->_get('action');
		if($action=='add'){
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Tk->add($data)){
				unset($data);
				$this->success("添加成功！");
			}
		}else if($action=='edit'){
			$map['id']=$this->_get('id');
			$this->tiaokuan=$Tk->where($map)->find();
			$this->display('edit_tiaokuan');
		}else if($action=='save'){
			$map['id']=$this->_get('id');
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Tk->where($map)->save($data)){
				unset($data);
				$this->success("修改成功！");
			}
		}else{
			$this->tiaokuan=$Tk->order('time desc')->select();
			$this->display();
		}
	}
	/*购物条款-end*/
    
	/*支付方式-start*/
	public function payment(){
		$Pay=M('Page_payment');
		$action=$this->_get('action');
		if($action=='add'){
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Pay->add($data)){
				unset($data);
				$this->success("添加成功！");
			}
		}else if($action=='edit'){
			$map['id']=$this->_get('id');
			$this->payment=$Pay->where($map)->find();
			$this->display('edit_payment');
		}else if($action=='save'){
			$map['id']=$this->_get('id');
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Pay->where($map)->save($data)){
				unset($data);
				$this->success("修改成功！");
			}
		}else{
			$this->payment=$Pay->order('time desc')->select();
			$this->display();
		}
	}
	/*支付方式-end*/
    
	/*配送方式-start*/
	public function shipping(){
		$Ship=M('Page_ship');
		$action=$this->_get('action');
		if($action=='add'){
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Ship->add($data)){
				unset($data);
				$this->success("添加成功！");
			}
		}else if($action=='edit'){
			$map['id']=$this->_get('id');
			$this->ship=$Ship->where($map)->find();
			$this->display('edit_shipping');
		}else if($action=='save'){
			$map['id']=$this->_get('id');
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Ship->where($map)->save($data)){
				unset($data);
				$this->success("修改成功！");
			}
		}else{
			$this->ship=$Ship->order('time desc')->select();
			$this->display();
		}
	}
	/*配送方式-end*/

	public function company(){
		$Company=M('Page_company');
		$type=$this->_get('type');
		$action=$this->_get('action');
		if($action=='save'){
			$data['title']=$this->_post('title');
			$data['content']=stripslashes($_POST['contents']);
			$data['time']=time();
			$map['type']=$type;
			if($Company->where($map)->save($data)){
				$this->success("修改成功！");
			}
		}else{
			$this->info=$Company->where("type='".$type."'")->find();
			$this->display();
		}
	}
    
	/*网站通告-start*/
	public function notice(){
		$Notice=M('Page_notice');
		$action=$this->_get('action');
		if($action=='add'){
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Notice->add($data)){
				unset($data);
				$this->success("添加成功！");
			}
		}else if($action=='edit'){
			$map['id']=$this->_get('id');
			$this->notice=$Notice->where($map)->find();
			$this->display('edit_notice');
		}else if($action=='save'){
			$map['id']=$this->_get('id');
			$data['title']=$this->_post('title');
			$data['disable']=$this->_post('disable');
			$data['content']=stripslashes($_POST['contents']);
            $data['time']=time();
			if($Notice->where($map)->save($data)){
				unset($data);
				$this->success("修改成功！");
			}
		}else{
			$this->notice=$Notice->order('time desc')->select();
			$this->display();
		}
	}
	/*网站通告-end*/
    
	/*招聘-start*/
	public function job(){
		$this->display();
	}
	/*招聘-end*/

    /*统一文章删除-start*/
	public function del(){
		$type=$this->_get('type');
		$map['id']=$this->_get('id');

		switch($type){
			case 'zn':
				$Zhinan=M('Page_zhinan');//购物指南
			    if($Zhinan->where($map)->delete()){echo '1';}else{echo '0';}
				break;
			case 'tk':
				$Tk=M('Page_tk');//购物条款
			    if($Tk->where($map)->delete()){echo '1';}else{echo '0';}
				break;
			case 'pay':
				$Tk=M('Page_payment');//支付方式
			    if($Tk->where($map)->delete()){echo '1';}else{echo '0';}
				break;
			case 'ship':
				$Tk=M('Page_ship');//配送方式
			    if($Tk->where($map)->delete()){echo '1';}else{echo '0';}
				break;
			case 'no':
				$Tk=M('Page_notice');//网站通知
			    if($Tk->where($map)->delete()){echo '1';}else{echo '0';}
				break;
		}
	}
	/*统一文章删除-end*/
	

}
?>

